package com.server.service;

import com.server.meta.MavenInfoMeta;
import com.server.util.Utils;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: sunguangzhu
 * Date: 14-2-13
 * Time: 上午11:01
 * To change this template use File | Settings | File Templates.
 */
public class PomGeneratorService {
    /**
     * 生成pom
     * @throws java.io.IOException
     */
    public void generatePom(GeneratorParams generatorParams,MavenInfoMeta mavenInfoMeta) throws IOException {
        String projectName = Utils.getSplitLast(generatorParams.getPath(), "/");
        if(mavenInfoMeta==null){
            mavenInfoMeta = new MavenInfoMeta();
            mavenInfoMeta.setGroupId(projectName);
            mavenInfoMeta.setArtifactId(projectName);
            mavenInfoMeta.setName(projectName);
            mavenInfoMeta.setPackaging("war");
            mavenInfoMeta.setVersion("1.0-SNAPSHOT");
        }
        Map root = new HashMap();
        root.put("bean", mavenInfoMeta);

        generatorParams.setTemplateName("pom");
        generatorParams.setRoot(root);
        new GeneratorService().generatePom(generatorParams);
    }
}
